package org.wangzhen.spring.event.orginal;

import java.util.EventObject;
import java.util.Vector;

/**
 * EventObject 代表一个事件源，是对事件的一个封装
 */
public class MyEventObject extends EventObject {

    private Vector<MyEventListener> listeners = new Vector<>();

    public void addListeners(MyEventListener listener) {
        listeners.add(listener);
    }

    /**
     * Constructs a prototypical Event.
     *
     * @param source The object on which the Event initially occurred.
     * @throws IllegalArgumentException if source is null.
     */
    public MyEventObject(Object source) {
        super(source);
    }

    public void publishChange() {
        for (MyEventListener listener : listeners) {
            listener.onEvent(this);
        }
    }




}
